package com.qifan.alb2b.service;



import org.springframework.stereotype.Service;

import com.qifan.alb2b.dao.CityInfoDao;
import com.qifan.alb2b.dao.CountryInfoDao;
import com.qifan.alb2b.domain.CountryInfoDomain;
import com.qifan.alb2b.exception.BusinessException;
import com.qifan.alb2b.util.DataGridModel;
import com.qifan.alb2b.util.Page;

/**
 * 国家业务层处理<br/>
 * 实际上对于CURD的操作本层确实有些鸡肋
 * @author hc24
 *
 */
@Service
public class CountryInfoService {
	private CountryInfoDao countryInfoDao;
	private CityInfoDao cityInfoDao;
	
	public void setCountryInfoDao(CountryInfoDao countryInfoDao) {
		this.countryInfoDao = countryInfoDao;
	}

	public void setCityInfoDao(CityInfoDao cityInfoDao) {
		this.cityInfoDao = cityInfoDao;
	}


	public Page query(DataGridModel dgm,CountryInfoDomain cid){
		return countryInfoDao.query(dgm, cid);
	}
	
	public CountryInfoDomain getCountryById(String cid){
		return countryInfoDao.getCountryById(cid);
	}
	
	public void add(CountryInfoDomain countryInfoDomain){
		countryInfoDao.add(countryInfoDomain);
	}
	
	public void update(CountryInfoDomain countryInfoDomain){
		countryInfoDao.update(countryInfoDomain);
	}
	
	public void delete(String id){
		if(cityInfoDao.queryCountByCountry(id)>0){
			throw new BusinessException("该国家下有相关联的城市信息，请先删除城市信息后再删除国家信息");
		}
		countryInfoDao.delete(new String[]{id});
	}
}
